#include "StdAfx.h"
#include "KeyboardInput.h"


namespace banknamespace
{
	Keyboard::Keyboard(HWND hWnd)
		: m_hWnd(hWnd)
	{
		{
			assert(hWnd != NULL);

			//fill the keyboard state array with 0s (false is key up)
			memset (keystates, 0 , 100);
			memset (pastKeystates, 0, 100);
		}
	}

	
	
	bool Keyboard::didGoUp(char key)
	{
		return !keystates[ key ] && pastKeystates[ key ];
	}

	bool Keyboard::didGoUp(int keyCode)
	{
		return !keystates[ keyCode ] && pastKeystates[ keyCode ];
	}

    bool Keyboard::didGoDown(char key)
	{
		return keystates[ key ] && !pastKeystates[ key ];
	}

	bool Keyboard::didGoDown(int keyCode)
	{
		return keystates[ keyCode ] && !pastKeystates[ keyCode ];
	}
	bool Keyboard::isDown(char key)
	{
		return keystates[ key ];
	}

	bool Keyboard::isDown(int keyCode)
	{
		return keystates[ keyCode ];
	}

	void Keyboard::update()
	{
		for(int i = 0; i < 256; ++i)
		{
			pastKeystates[i] = keystates[i];
		}
	}

	void Keyboard::processMessages(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
		switch(message)
		{
		case WM_KEYDOWN:
			{
				keystates[wParam] = true;
			}
			break;
		case WM_KEYUP:
			{
				//char key = MapVirtualKey(wParam, MAPVK_VK_TO_CHAR); //convert KeyCode to char
				keystates[wParam] = false;
			}
			break;
		}
	}

	Keyboard& GetTheKeyboard(HWND hWnd)
	{
		static Keyboard Keyboard(hWnd);
		return Keyboard;
	}
}
